
package us.hornerscorners.lollipop.hapi;

/*
 * #%L
 * LollipopRouter
 * %%
 * Copyright (C) 2013 - 2014 Jim Horner
 * %%
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public
 * License along with this program.  If not, see
 * <http://www.gnu.org/licenses/gpl-3.0.html>.
 * #L%
 */

import java.util.Map;

import ca.uhn.hl7v2.HL7Exception;

import ca.uhn.hl7v2.protocol.ReceivingApplicationExceptionHandler;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


/**
 * Class description
 *
 *
 * @version        v1.0, 2014-09-07
 * @author         Jim Horner    
 */
public class HL7ExceptionHandler implements ReceivingApplicationExceptionHandler {

    /** Field description */
    private final Logger logger = LoggerFactory.getLogger(getClass());

    /**
     * Constructs ...
     *
     *
     */
    public HL7ExceptionHandler() {

        super();
    }

    /**
     * Method description
     *
     *
     * @param inMessage
     * @param metadata
     * @param outMessage
     * @param exception
     *
     * @return
     *
     * @throws HL7Exception
     */
    @Override
    public String processException(String inMessage, Map<String, Object> metadata,
                                   String outMessage, Exception exception)
            throws HL7Exception {

        if (outMessage != null) {

            logger.debug("Response Message [\n{}\n]", outMessage.trim());
        }

        return outMessage;
    }
}
